package com.atguigu.gulimail.gulimailsearch.thread;

import com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.util.concurrent.DefaultThreadFactory;

import java.util.concurrent.*;

import static com.alibaba.nacos.api.cmdb.pojo.PreservedEntityTypes.service;

public class ThreadTest {

//    public static ExecutorService executor = Executors.newFixedThreadPool(10);
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        System.out.println("main-----start------");
//        Thread01 thread = new Thread01();
//        thread.start();
//
//
//        System.out.println("main-----end------");



//
//        System.out.println("main-----start------");
//        Runnable01 runnable01 = new Runnable01();
//        new Thread(runnable01).start();
//        System.out.println("main-----end------");


//        System.out.println("main-----start------");
//        FutureTask<Integer> futureTask = new FutureTask<>(new Callable01());
//        new Thread(futureTask).start();
//
//        Integer integer = futureTask.get();
//        System.out.println("main-----end------"+integer);




//        executor.execute(new Runnable01());


//        int corePoolSize,
//        int maximumPoolSize,
//        long keepAliveTime,
//        TimeUnit unit,
//        BlockingQueue<Runnable> workQueue,
//        ThreadFactory threadFactory,
//        RejectedExecutionHandler handler


        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5,200,10,TimeUnit.SECONDS,new LinkedBlockingQueue<>(100000),Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
        threadPoolExecutor.submit(new Callable01());
        threadPoolExecutor.shutdown();

    }
    public static class Thread01 extends Thread{
        @Override
        public void run(){
            System.out.println("当前线程："+Thread.currentThread().getId());
            int i = 10/2;
            System.out.println("运行结果："+i);
        }
    }
    public static class Runnable01 implements Runnable{

        @Override
        public void run() {
            System.out.println("当前线程："+Thread.currentThread().getId());
            int i = 10/2;
            System.out.println("运行结果："+i);
        }
    }

    public static class Callable01 implements Callable<Integer>{

        @Override
        public Integer call() throws Exception {
            System.out.println("当前线程："+Thread.currentThread().getId());
            int i = 10/2;
            System.out.println("运行结果："+i);
            return i;
        }
    }

}
